﻿<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="mapa.aspx.vb" Inherits="geriatria.mapa" %>

<!DOCTYPE html>
<html>
<head>
    <title>Google Maps JavaScript API v3 Example: Map Simple</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta charset="UTF-8">
    <style type="text/css">
        html, body, #map_canvas
        {
            margin: 0;
            padding: 0;
            height: 100%;
        }
    </style>
    <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script src="js/jquery.min.js" type="text/javascript"></script>
    <link href="css/principal.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var map;
        var geocoder;
        var tmpControl = 0;
        function initialize() {
            geocoder = new google.maps.Geocoder();
            var latlng = new google.maps.LatLng(4.570868, -74.297332);
            var myOptions = {
                zoom: 18,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.HYBRID
            }
            map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
            $('#direccion').val(<%= Request.QueryString.Get("direccion") %>);
        }

        function codeAddress(vadress) {
            var address = "";
            if(vadress == undefined)
                address = <%= Request.QueryString.Get("direccion") %>;
            else
                address = vadress;
            if (geocoder) {
                geocoder.geocode({ 'address': address }, function (results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        map.setCenter(results[0].geometry.location);
                        switch(results[0].geometry.location_type){
                        case 'ROOFTOP':
                            $("#divMensajeGeo").css("color","green").html("Ubicación exacta");
                        break;
                        default:
                            $("#divMensajeGeo").css("color","red").html("Ubicación aproximada");
                        break;
                        }
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location
                        });
                    } else {
                        alert("No fue posible la reubicación por la siguiente causa \n: " + status);
                    }
                });
            }
        }
    </script>
</head>
<body onload="initialize();codeAddress();">
    <div id="divMensajeGeo" class="">
    </div>
    <div id="divFormulario">
        <label for="direccion">
            Ubicación</label>
        <input type="text" id="direccion" />
        <input type="button" id="btnBoton" value="Consultar ubicación" onclick="codeAddress($('#direccion').val());" />
    </div>
    <div id="map_canvas">
    </div>
</body>
</html>
